package com.mcm.service;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import tool.MyApplicationContext;



import com.mcm.mapper.*;
import com.mcm.model.*;




/**
 * 单例模式 分销系统的user服务类，用于数据同步
 * 
 * @author chz
 * 
 */

public class CustomerService {
	// 单例模式 start
	private volatile static CustomerService instance = null;
	private ApplicationContext ac = null;
	private CustomerMapper customerMapper;
	private CustomerShopMapper customerShopMapper;
	private CustomerService() {
//		this.ac = new ClassPathXmlApplicationContext("/config/spring-common-mssql.xml");
		this.ac = MyApplicationContext.mssql_ac;
		this.customerMapper =  ac.getBean(CustomerMapper.class);
		this.customerShopMapper =  ac.getBean(CustomerShopMapper.class);
	}

	public static CustomerService getInstance() {
		if (instance == null) {
			synchronized (CustomerService.class) {// 1
				if (instance == null) {// 2
					instance = new CustomerService();// 3
				}
			}
		}
		return instance;
	}
	// 单例模式 end
	
//	test
	public static void main(String[] args){

//		String s = CustomerService.getInstance().getCustomerMapper().selectByPrimaryKey(1).getNickname();
//		System.out.println(s);
		// 测试数据库是否可写
//		Customer record= new Customer();
//		record.setAddress("成都");
//		record.setNickname("昵称");
//		int i = CustomerService.getInstance().getCustomerMapper().insert(record);
//		System.out.println(i);
		
		CustomerShop shop =CustomerService.getInstance().getCustomerShopMapper().selectByCustomerID(3);
		System.out.println(shop.getChannelcode());
		
		
	}

	public CustomerMapper getCustomerMapper() {
		return customerMapper;
	}

	public CustomerShopMapper getCustomerShopMapper() {
		return customerShopMapper;
	}

	
	
}